package com.tudouji.project.dept.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.dept.domain.DeptStoreroom;
import com.tudouji.project.dept.service.IDeptStoreroomService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 库房部门对照Controller
 * 
 * @author tudouji
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/dept/deptstoreroom")
public class DeptStoreroomController extends BaseController
{
    @Autowired
    private IDeptStoreroomService deptStoreroomService;

    /**
     * 查询库房部门对照列表
     */
    @PreAuthorize("@ss.hasPermi('dept:deptstoreroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptStoreroom deptStoreroom)
    {
        startPage();
        List<DeptStoreroom> list = deptStoreroomService.selectDeptStoreroomList(deptStoreroom);
        return getDataTable(list);
    }

    /**
     * 通过部门查询库房
     */
    @GetMapping("/getStorerooms")
    public AjaxResult getStorerooms(DeptStoreroom deptStoreroom)
    {
        List<DeptStoreroom> list = deptStoreroomService.selectDeptStoreroomList(deptStoreroom);
        return AjaxResult.success(list);
    }

    /**
     * 导出库房部门对照列表
     */
    @PreAuthorize("@ss.hasPermi('dept:deptstoreroom:export')")
    @Log(title = "库房部门对照", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeptStoreroom deptStoreroom)
    {
        List<DeptStoreroom> list = deptStoreroomService.selectDeptStoreroomList(deptStoreroom);
        ExcelUtil<DeptStoreroom> util = new ExcelUtil<DeptStoreroom>(DeptStoreroom.class);
        return util.exportExcel(list, "deptstoreroom");
    }

    /**
     * 获取库房部门对照详细信息
     */
    @PreAuthorize("@ss.hasPermi('dept:deptstoreroom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deptStoreroomService.selectDeptStoreroomById(id));
    }

    /**
     * 新增库房部门对照
     */
    @PreAuthorize("@ss.hasPermi('dept:deptstoreroom:add')")
    @Log(title = "库房部门对照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeptStoreroom deptStoreroom)
    {
        List<DeptStoreroom> deptStoreroomList = deptStoreroomService.selectDeptStoreroomList(deptStoreroom);
        if (deptStoreroomList.size() > 0){
            return AjaxResult.error("已存在对照关系！");
        }
        return toAjax(deptStoreroomService.insertDeptStoreroom(deptStoreroom));
    }

    /**
     * 修改库房部门对照
     */
    @PreAuthorize("@ss.hasPermi('dept:deptstoreroom:edit')")
    @Log(title = "库房部门对照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptStoreroom deptStoreroom)
    {
        List<DeptStoreroom> deptStoreroomList = deptStoreroomService.selectDeptStoreroomList(deptStoreroom);
        if (deptStoreroomList.size() > 0){
            return AjaxResult.error("已存在对照关系！");
        }
        return toAjax(deptStoreroomService.updateDeptStoreroom(deptStoreroom));
    }

    /**
     * 删除库房部门对照
     */
    @PreAuthorize("@ss.hasPermi('dept:deptstoreroom:remove')")
    @Log(title = "库房部门对照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deptStoreroomService.deleteDeptStoreroomByIds(ids));
    }
}
